<%@page import="cn.sendto.model.ClassEntity"%>
<%@page import="cn.sendto.mapper.ClassMapper"%>
<%@page import="java.util.List"%>
<%@page import="cn.sendto.mapper.StudentMapper"%>
<%@page import="cn.sendto.model.StudentEntity"%>
<%@page import="cn.sendto.mapper.IRowMapper"%>
<%@page import="cn.sendto.dbhelper.DBHelper"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
   if(request.getSession().getAttribute("user")==null){
	   request.getRequestDispatcher("login.jsp").forward(request, response);
   }

%>
    <% 
     request.setCharacterEncoding("utf-8");
     String id=request.getParameter("id");
     DBHelper helper=new DBHelper();
     IRowMapper mapper=new StudentMapper();
     final String QUERY="select * from studentinfo s,classinfo c where s.classid=c.classid and studentid=?";
     List<StudentEntity> list=helper.executeQuery(QUERY, mapper, id);
     helper.close();
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/main.css" />
</head>

<body class="add">
	<div class="add_div">
		<form action="update.jsp" method="post">
			<div class="add_item">
				<span>姓名：<input type="text" name="studentname" value="<%=list.get(0).getStudentName()%>">
				</span>
			</div>
			<div class="add_item">
				<span> 性别： <select name="gender">
						<option
						 value="男" <%if(list.get(0).getGender().equals("男")){out.print("selected=selected ");}%>>
						 男
						 </option>
						<option
						 value="女" <%if(list.get(0).getGender().equals("女")){out.print("selected=selected ");}%>>
						  女
						  </option>
				</select>
				</span>
			</div>
			<div class="add_item">
				<span>年龄：<input name="age" type="number" value="<%=list.get(0).getAge()%>"/>
				</span>
			</div>
			<div class="add_item">
				<span>学号：<input name="studentno" type="text" value="<%=list.get(0).getStudentno()%>"/>
				</span>
			</div>
			<div class="add_item">
				<span>地址：<input name="address" type="text" value="<%=list.get(0).getAddress()%>"/>
				</span>
			</div>
			<div class="add_item">
				<span>电话：<input name="tel" type="text" value="<%=list.get(0).getTel()%>"/>
				</span>
			</div>
			<div class="add_item">
				<span> 班级： <select name="classid">
				<%
				IRowMapper classMapper=new ClassMapper();
			    final String CLASSQUERY="select * from classinfo";
			    List<ClassEntity> classList=helper.executeQuery(CLASSQUERY, classMapper, null);
			    	for(int i=0;i<classList.size();i++){
			    		if(list.get(0).getClassId()==classList.get(i).getClassId()){
			    			out.print("<option value=\""+classList.get(i).getClassId()+"\" selected=selected>"+classList.get(i).getClassName()+"</option>");
			    		} else{
			    			out.print("<option value=\""+classList.get(i).getClassId()+"\">"+classList.get(i).getClassName()+"</option>");
			    		}
			    	}
			    helper.close();
			    	
			    
				%>
	
				</select>
				</span>
			</div>
			<input type="hidden" value="<%=list.get(0).getStudentId()%>" name="studentid"/>
			<div class="btn">
				<input type="submit" value="提交" />
			</div>
		</form>
	</div>

</body>

</html>